package com.example.test.dialogfactory;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.widget.LinearLayout;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager2.widget.ViewPager2;
import com.example.test.dialogfactory.MainActivity35.Adapter;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.tabs.TabLayout.Tab;
import com.google.android.material.tabs.TabLayoutMediator;
import com.google.android.material.tabs.TabLayoutMediator.TabConfigurationStrategy;
import com.scwang.smart.refresh.footer.ClassicsFooter;
import com.scwang.smart.refresh.header.ClassicsHeader;
import com.scwang.smart.refresh.layout.SmartRefreshLayout;
import com.scwang.smart.refresh.layout.api.RefreshLayout;
import com.scwang.smart.refresh.layout.listener.OnRefreshListener;

public class MainActivity36 extends AppCompatActivity {

    private SmartRefreshLayout mRefresh;
    private ViewPager2 mViewpager;
    private LinearLayout mContainer;
    private TabLayout mTabLayout;

    public static void start( Context context ) {

        Intent starter = new Intent( context, MainActivity36.class );
        context.startActivity( starter );
    }

    @Override
    protected void onCreate( Bundle savedInstanceState ) {

        super.onCreate( savedInstanceState );
        setContentView( R.layout.activity_main36 );
        initView();
        initViewAction();
    }

    private void initView() {

        mRefresh = (SmartRefreshLayout) findViewById( R.id.refresh );
        mViewpager = (ViewPager2) findViewById( R.id.viewpager );
        mContainer = (LinearLayout) findViewById( R.id.container );
        mTabLayout = (TabLayout) findViewById( R.id.tabLayout );
    }

    private void initViewAction() {

        mRefresh.setOnRefreshListener( new OnRefreshListener() {
            @Override
            public void onRefresh( @NonNull RefreshLayout refreshLayout ) {

                mRefresh.postDelayed( new Runnable() {
                    @Override
                    public void run() {

                        mRefresh.finishRefresh();
                    }
                }, 3000 );
            }
        } );
        mRefresh.setEnableLoadMore( false );
        mRefresh.setEnableAutoLoadMore( false );

        mRefresh.setRefreshHeader( new ClassicsHeader( this ) );
        mRefresh.setRefreshFooter( new ClassicsFooter( this ) );

        mViewpager.setAdapter( new Adapter( this ) );

        new TabLayoutMediator( mTabLayout, mViewpager, new TabConfigurationStrategy() {
            @Override
            public void onConfigureTab( @NonNull Tab tab, int position ) {

                tab.setText( "tab: " + position );
            }
        } ).attach();
    }
}